import store from '@/store'
import Vue from 'vue'
import VueRouter from 'vue-router'

Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    name: 'manage',
    component: () => import('../views/Manage.vue'),
    redirect: "/home",
    children: [
        { path: 'home', name: 'home', meta: { label: '首页' }, component: () => import('../views/home/Home.vue'),},
        { path: 'carouselManagement', name: 'carouselManagement', meta: { label: '前台首页管理/轮播图管理' },component: () => import('../views/front-homepage-management/CarouselManagement'),},
        { path: 'recommendedProduct', name: 'recommendedProduct', meta: { label: '前台首页管理/推荐商品管理' },component: () => import('../views/front-homepage-management/RecommendedProduct'),},
        { path: 'goodsManagement', name: 'goodsManagement', meta: { label: '商品/商品管理' },component: () => import('../views/goods/GoodsManagement'),},
        { path: 'goodsClassify', name: 'goodsClassify', meta: { label: '商品/商品分类' },component: () => import('../views/goods/GoodsClassify'),},
        { path: 'orderManagement', name: 'orderManagement', meta: { label: '订单管理' },component: () => import('../views/order-management/OrderManagement'),},
        { path: 'userManagement', name: 'userManagement', meta: { label: '用户管理' },component: () => import('../views/user-management/UserManagement'),},
        { path: 'changePassword', name: 'changePassword', meta: { label: '系统管理/修改密码' },component: () => import('../views/system-management/ChangePassword'),},
        { path: 'loggingOut', name: 'loggingOut', meta: { label: '系统管理/安全退出' },component: () => import('../views/system-management/LoggingOut'),},
        { path: 'personalCenter', name: 'personalCenter', meta: { label: '个人中心' },component: () => import('../views/personal-center/PersonalCenter'),},
        {
            path: 'user',
            name: 'user',
            component: () => import('../views/User'),
          }

    ]
  },

]

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})

router.beforeEach((to, from, next) => {
    localStorage.setItem("currentPathName", to.meta.label) // 设置当前路由名称
    store.commit('setPath')  // 触发store的数据更新
    next() // 放行路由
})

export default router
